Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for block pruning #116

Merged
merged 4 commits into from
Dec 7, 2024
Merged

Add support for block pruning #116

merged 4 commits into from
Dec 7, 2024

Conversation

lukechampine
Copy link
Member

Been a long time coming. 😅

The strategy here is quite naive, but I think it will be serviceable. Basically, when we apply a block N, we delete block N-P. P is therefore the "prune target," i.e. the maximum number of blocks you want to store.

In practice, this isn't exhaustive: it only deletes blocks from the best chain. It also won't dramatically shrink the size of an existing database. I think this is acceptable, because pruning is most important during the initial sync, and during the initial sync, you'll only be receiving blocks from one chain at a time. Also, we don't want to make pruning too easy; after all, we need a good percentage of nodes to be storing the full chain, so that others can sync to them.

I tested this out locally with a prune target of 1000, and after syncing 400,000 blocks, my consensus.db was around 18 GB. This is disappointing; it should be much smaller. With some investigation, I found that the Bolt database was only storing ~5 GB of data (most of which was the accumulator tree, which we can't prune until after v2). I think this is a combination of a) Bolt grows the DB capacity aggressively in response to writes, and b) Bolt never shrinks the DB capacity. So it's possible that we could reduce this number by tweaking our DB batching parameters. Alternatively, we could provide a tool that copies the DB to a new file. Not the most user-friendly, but again, I think I'm okay with that for now.

Depends on SiaFoundation/core#228

chain/manager.go Outdated Show resolved Hide resolved
Copy link
Member

@ChrisSchinnerl ChrisSchinnerl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is pretty scary. It seems like pruning is now done but I think the way it is now isn't safe for the network.

We now have a state where users might prune blocks without the syncer notifying other peers about not being full node. So imo this is only safe to use once we have a solution for that.

Imo that involves signaling whether you are a full node and what your latest known block is. Then have the syncer only connect to peers which are either full nodes or "partial" nodes >= your required block height. Otherwise we might run into weird issues and network fragmentation in the worst case.

.changeset/add_support_for_block_pruning.md Outdated Show resolved Hide resolved
testutil/syncer.go Show resolved Hide resolved
@lukechampine
Copy link
Member Author

We should definitely test what happens when you try to sync from a pruned node. Looking at BlocksForHistory, I think the RPC will just fail, and you'll switch to a different peer. Seems fine to me.

@n8maninger
Copy link
Member

n8maninger commented Dec 5, 2024

RPC will just fail, and you'll switch to a different peer

Will the pruned peer ever be dinged enough to be banned? That could cause problems if the pruned node ends up banned by all the full nodes over time for errored RPC 🤔

@lukechampine
Copy link
Member Author

Currently syncLoop doesn't penalize failed syncs at all, it just logs the error.

n8maninger
n8maninger previously approved these changes Dec 7, 2024
@n8maninger n8maninger merged commit ed9bce1 into master Dec 7, 2024
10 checks passed
@n8maninger n8maninger deleted the prune branch December 7, 2024 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants